html_format(name(Value,N), Field, input(text, [name=Field, size=N, value=Value]), unidimensional, _) :- !.

html_format(textinput(Value, Rows, Cols), Field, textinput(Field, [rows=Rows, cols=Cols], Value), bidimensional, public) :- !.

html_format(textinput(Value, _Rows, _Cols), Field, tt(Value), bidimensional, private) :- !.

html_format(number(Value,N), Field, input(number, [name=Field, size=N, value=Value]), unidimensional, public) :- !.

html_format(number(Value,_N), Field, tt(Value), unidimensional, private) :- !.

html_format(password(Value ,N), Field, input(password, [name=Field, size=N, value=Value]), unidimensional, public) :- !.

html_format(password(Value ,_N), Field, tt('forbidden'), unidimensional, private) :- !.

html_format(checkbox(State), Field, checkbox(Field, State), plain, _) :- !.

html_format(menu(Size, Att, Fields), Field, menu(Field, [size=Size, Att], Fields), plain, _) :- !.

html_format(input_img(Value, N), Field, [input(text, [name=Field, size=N, value=Value]),\\, blockquote(img$[src=Value])], unidimensional, public) :- !.

html_format(input_img(Value, _N), Field, blockquote(img$[src=Value]), unidimensional, private) :- !.

html_format(input_link(Value, N), Field, [input(text, [name=Field, size=N, value=Value]),\\, blockquote(ref(PValue, PValue))], unidimensional, public) :- !,
	ensure_http_header(Value, PValue).	

html_format(input_link(Value, _N), Field, ref(Value, Value), unidimensional, private) :- !,
	ensure_http_header(Value, PValue).

html_format(invisible(Value,N), Field, input(hidden, [name=Field, size=N, value=Value]), unidimensional, public) :- !.

html_format(invisible(Value,N), Field, input(hidden, [name=Field, size=N, value=Value]), unidimensional, private) :- !.

html_format(invisible_searchable(Value,N), Field, input(hidden, [name=Field, size=N, value=Value]), unidimensional, public) :- !.

html_format(invisible_searchable(Value,N), Field, input(text, [name=Field, size=N, value=Value]), unidimensional, private) :- !.

html_format(invisible_searchable_date(Value,N), Field, input(hidden, [name=Field, size=N, value=Value]), unidimensional, public) :- !.

html_format(invisible_searchable_date(Value,N), Field, [input(text, [name=Field, size=N, value=Value]), checkbox(Field_ck, State)], unidimensional, private) :- !, 
	atom_concat(Field, '_ck', Field_ck).

html_format(name_ck(Value,N,_), Field, [ref(URL, small("Info")), span(' '), input(text, [name=Field, size=N, value=Value])], unidimensional, public) :- !, atom_concat('info.html#', Field, URL).

html_format(name_ck(Value, N, State), Field, [input(text, [name=Field, size=N, value=Value]), checkbox(Field_ck, State)], unidimensional, private) :- !, atom_concat(Field, '_ck', Field_ck).

html_format(textinput_ck(Value, Rows, Cols, _State), Field, [ref(URL, small("Info")), span(' '), textinput(Field, [rows=Rows, cols=Cols], Value)], bidimensional, public) :- !, atom_concat('info.html#', Field, URL).
	

html_format(textinput_ck(Value, Rows, Cols, State), Field, [textinput(Field, [rows=Rows, cols=Cols], Value), checkbox(Field_ck, State)], bidimensional, private) :- !, 
	atom_concat(Field, '_ck', Field_ck).

html_format(number_ck(Value,N,_), Field, [ref(URL, small("Info")), span(' '), input(number, [name=Field, size=N, value=Value])], unidimensional, public) :- !, 
	atom_concat('info.html#', Field, URL).

html_format(number_ck(Value, N, State), Field, [input(number, [name=Field, size=N, value=Value]), checkbox(Field_ck, State)], unidimensional, private) :- !, 
	atom_concat(Field, '_ck', Field_ck).

html_format(input_link_ck(Value, N, _State), Field, [ref(URL, small("Info")), span(' '), input(text, [name=Field, size=N, value=Value]), \\, blockquote(ref(PValue, PValue))], unidimensional, public) :-  !, 
	atom_concat('info.html#', Field, URL),
	ensure_http_header(Value, PValue).

html_format(input_link_ck(Value, N, State), Field, [input(text, [name=Field, size=N, value=Value]), checkbox(Field_ck, State),\\, blockquote(ref(PValue, PValue))], unidimensional, private) :- !, 
	atom_concat(Field, '_ck', Field_ck),
	ensure_http_header(Value, PValue).

html_format(multiple_menu_ck(Values, N, M, _State), Field, HTML, plain, public) :- !, 
	atom_concat('info.html#', Field, URL),
	HTML = [
		   ref(URL, small("Info")),
		   span(' '), 
		   Menus
	       ],
	generate_menus(Values, Field, N, M, Menus).

html_format(multiple_menu_ck(Values, N, M, State), Field, HTML, plain, private) :- !, 
	atom_concat(Field, '_ck', Field_ck),
	HTML = [
		   Menus, 
		   checkbox(Field_ck, State)
	       ],
	generate_menus(Values, Field, N, M, Menus).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Defining elements which are to be compulsory in a form:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

html_format(name_rq(Value,N), Field, input(text, [name=Field, size=N, value=Value]), unidimensional, _) :- !.

html_format(textinput_rq(Value, Rows, Cols), Field, textinput(Field, [rows=Rows, cols=Cols], Value), bidimensional, public) :- !.

html_format(textinput_rq(Value, _Rows, _Cols), Field, tt(Value), bidimensional, private) :- !.

html_format(number_rq(Value,N), Field, input(number, [name=Field, size=N, value=Value]), unidimensional, public) :- !.

html_format(number_rq(Value,_N), Field, tt(Value), unidimensional, private) :- !.

html_format(password_rq(Value ,N), Field, input(password, [name=Field, size=N, value=Value]), unidimensional, public) :- !.

html_format(password_rq(Value ,_N), Field, tt('forbidden'), unidimensional, private) :- !.

html_format(checkbox_rq(State), Field, checkbox(Field, State), plain, _) :- !.

html_format(menu_rq(Size, Att, Fields), Field, menu(Field, [size=Size, Att], Fields), plain, _) :- !.

html_format(input_img_rq(Value, N), Field, [input(text, [name=Field, size=N, value=Value]),\\, blockquote(img$[src=Value])], unidimensional, public) :- !.

html_format(input_img_rq(Value, _N), Field, blockquote(img$[src=Value]), unidimensional, private) :- !.

html_format(input_link_rq(Value, N), Field, [input(text, [name=Field, size=N, value=Value]),\\, blockquote(ref(PValue, PValue))], unidimensional, public) :- !,
	ensure_http_header(Value, PValue).	

html_format(input_link_rq(Value, _N), Field, blockquote(ref(Value, Value)), unidimensional, private) :- !,
	ensure_http_header(Value, PValue).

html_format(invisible_rq(Value,N), Field, input(hidden, [name=Field, size=N, value=Value]), unidimensional, public) :- !.

html_format(invisible_rq(Value,N), Field, input(hidden, [name=Field, size=N, value=Value]), unidimensional, private) :- !.

html_format(invisible_searchable_rq(Value,N), Field, input(hidden, [name=Field, size=N, value=Value]), unidimensional, public) :- !.

html_format(invisible_searchable_rq(Value,N), Field, input(text, [name=Field, size=N, value=Value]), unidimensional, private) :- !.

html_format(invisible_searchable_date_rq(Value,N), Field, input(hidden, [name=Field, size=N, value=Value]), unidimensional, public) :- !.

html_format(invisible_searchable_date_rq(Value,N), Field, [input(text, [name=Field, size=N, value=Value]), checkbox(Field_ck, State)], unidimensional, private) :- !, 
	atom_concat(Field, '_ck', Field_ck).

html_format(name_rq_ck(Value,N,_), Field, [ref(URL, small("Info")), span(' '), input(text, [name=Field, size=N, value=Value])], unidimensional, public) :- !, 
	atom_concat('info.html#', Field, URL).

html_format(name_rq_ck(Value, N, State), Field, [input(text, [name=Field, size=N, value=Value]), checkbox(Field_ck, State)], unidimensional, private) :- !, 
	atom_concat(Field, '_ck', Field_ck).

html_format(textinput_rq_ck(Value, Rows, Cols, _State), Field, [ref(URL, small("Info")), span(' '), textinput(Field, [rows=Rows, cols=Cols], Value)], bidimensional, public) :- !, atom_concat('info.html#', Field, URL).
	

html_format(textinput_rq_ck(Value, Rows, Cols, State), Field, [textinput(Field, [rows=Rows, cols=Cols], Value), checkbox(Field_ck, State)], bidimensional, private) :- !, 
	atom_concat(Field, '_ck', Field_ck).

html_format(number_rq_ck(Value,N,_), Field, [ref(URL, small("Info")), span(' '), input(number, [name=Field, size=N, value=Value])], unidimensional, public) :- !, 
	atom_concat('info.html#', Field, URL).

html_format(number_rq_ck(Value, N, State), Field, [input(number, [name=Field, size=N, value=Value]), checkbox(Field_ck, State)], unidimensional, private) :- !, 
	atom_concat(Field, '_ck', Field_ck).

html_format(input_link_rq_ck(Value, N, State), Field, [ref(URL, small("Info")), span(' '), input(text, [name=Field, size=N, value=Value]), \\, blockquote(ref(PValue, PValue))], unidimensional, public) :-  !, 
	atom_concat('info.html#', Field, URL),
	ensure_http_header(Value, PValue).

html_format(input_link_rq_ck(Value, N, State), Field, [input(text, [name=Field, size=N, value=Value]), checkbox(Field_ck, State),\\, blockquote(ref(PValue, PValue))], unidimensional, private) :- !, 
	atom_concat(Field, '_ck', Field_ck),
	ensure_http_header(Value, PValue).

html_format(multiple_menu_rq_ck(Values, N, M,_), Field, HTML, plain, public) :- !, 
	html_format(multiple_menu_ck(Values, N, M, _State), Field, HTML, plain, public).
html_format(multiple_menu_rq_ck(Values, N, M, State), Field, HTML, plain, private) :- !, 
	html_format(multiple_menu_ck(Values, N, M, State), Field, HTML, plain, private) .
	
